<%@page import="fr.perso.spring.SimpleBean"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="java.util.Arrays"%>
<%@page import="java.util.Enumeration"%>
<%@page import="org.springframework.aop.framework.Advised"%>
<%@page import="org.springframework.aop.support.AopUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>

<html>
<head>
<title>Spring Framework Beans</title>
</head>
<body>
<h1>display bean </h1>
<%
    try {
        Enumeration<String> servletContextAttributeNames = application.getAttributeNames();
        
        while (servletContextAttributeNames.hasMoreElements()) {
            String servletContextAttributeName = servletContextAttributeNames.nextElement();
            Object servletContextAttribute = application.getAttribute(servletContextAttributeName);
            if (servletContextAttribute instanceof ApplicationContext) {
                
                ApplicationContext applicationContext = (ApplicationContext)servletContextAttribute;
 				
                out.println("<h1>" + applicationContext.getDisplayName() + "</h1>");
                out.println("<p>ServletContext.attribute : " + servletContextAttributeName + "</p>");
                out.println("<p>ApplicationContext : " + applicationContext + "</p>");
                
                SimpleBean myBean = (SimpleBean)applicationContext.getBean("simpleBean");
                if(myBean!=null) {
                	out.println(" attr1:" + myBean.getAttr1() + "<br/>");
                	out.println(" attr2:" + myBean.getAttr2() + "<br/>");
                }
            }
        }
    } catch (Exception e) {
        PrintWriter printWriter = new PrintWriter(out);
        e.printStackTrace(printWriter);
        out.println();
        printWriter.flush();
    }
%>
</body>
</html>